home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Control del ratón / CaptureLoss / CaptureLoss.cs next >
Encoding:
Text File  |  2002-04-18  |  1.3 KB  |  55 lines

  1. //------------------------------------------
  2. // CaptureLoss.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class CaptureLoss: Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new CaptureLoss());
  13.      }
  14.      public CaptureLoss()
  15.      {
  16.           Text = "PΘrdida de captura";
  17.  
  18.                // Usar el objeto NativeWindow.
  19.  
  20.           CaptureLossWindow win = new CaptureLossWindow();
  21.           win.form = this;
  22.           win.AssignHandle(Handle);
  23.      }
  24.      protected override void OnMouseDown(MouseEventArgs mea)
  25.      {
  26.           Invalidate();
  27.      }
  28.      public void OnLostCapture()
  29.      {
  30.           Invalidate();
  31.      }
  32.      protected override void OnPaint(PaintEventArgs pea)
  33.      {
  34.           Graphics grfx = pea.Graphics;
  35.  
  36.           if (Capture)
  37.                grfx.FillRectangle(Brushes.Red, ClientRectangle);
  38.           else
  39.                grfx.FillRectangle(Brushes.Gray, ClientRectangle);
  40.      }
  41. }
  42.  
  43. class CaptureLossWindow: NativeWindow 
  44. {
  45.      public CaptureLoss form;
  46.  
  47.      protected override void WndProc(ref Message message) 
  48.      {
  49.           if (message.Msg == 533)                 // WM_CAPTURECHANGED
  50.                form.OnLostCapture();
  51.  
  52.           base.WndProc(ref message);
  53.      }
  54. }
  55.